package com.weishenai.customerassistant.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weishenai.customerassistant.common.Result;
import com.weishenai.customerassistant.entity.FactFinder;
import com.weishenai.customerassistant.service.FactFinderService;
import com.weishenai.customerassistant.service.SubstationService;
import com.weishenai.customerassistant.utils.DateUtil;
import com.weishenai.customerassistant.utils.WeChatUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "管理系统_检察员信息")
@RestController
@RequestMapping("/fact")
public class FactFinderController extends BaseController{
    @Autowired
    private FactFinderService factFinderService;

    @PreAuthorize("hasAuthority('inspectors:list:delete')")
    @ApiOperation("根据微信ID删除一个检察员")
    @ApiImplicitParam(name = "weixinId", value = "获取的微信ID号码")
    @PostMapping("/del/{weixinId}")
    public Object delFactFinder(@PathVariable("weixinId") String weixinId) {
        Integer result = factFinderService.delFactFinder(weixinId);
        return result > 0 ? Result.success() : Result.failed("该用户不存在");
    }

    @PreAuthorize("hasAuthority('inspectors:list')")
    @ApiOperation("根据供电所查询，支持模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "substation", value = "所属供电所"),
            @ApiImplicitParam(name = "pageNum", value = "第几页"),
            @ApiImplicitParam(name = "pageSize", value = "每一页的数量"),
            @ApiImplicitParam(name = "factName", value = "检察员名字")
    })
    @PostMapping("/select/{substation}/{pageNum}/{pageSize}/{factName}")
    public Object selectByName(@PathVariable(name = "substation") String substation, @PathVariable(name = "pageNum") Integer pageNum, @PathVariable(name = "pageSize") Integer pageSize, @PathVariable("factName") String factName) {
        IPage<FactFinder> result = factFinderService.selectByFactName(substation,pageNum, pageSize, factName);
        return result.getRecords() != null ? Result.success(result) : Result.failed("该用户不存在");
    }

    @PreAuthorize("hasAuthority('inspectors:list')")
    @ApiOperation("查询所有的检察员信息，支持模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "substation", value = "所属供电所"),
            @ApiImplicitParam(name = "pageNum", value = "第几页"),
            @ApiImplicitParam(name = "pageSize", value = "每一页的数量"),
    })
    @PostMapping("/select/{substation}/{pageNum}/{pageSize}")
    public Object selectAll(@PathVariable(name = "substation") String substation,@PathVariable(name = "pageNum") Integer pageNum, @PathVariable(name = "pageSize") Integer pageSize) {
        IPage<FactFinder> result = factFinderService.selectAll(substation,pageNum, pageSize);
        return result.getRecords() != null ? Result.success(result) : Result.failed("该用户不存在");
    }

    @ApiOperation("获取当前供电所检察员列表")
    @ApiImplicitParam(name = "substation",value = "供电所名称")
    @GetMapping("/select/{substation}")
    public Object selectBySubstation(@PathVariable(name = "substation") String substation){
        return Result.success(factFinderService.listFactFinder(substation));
    }
}
